#include "filestream.h"
#include <cstring>

using namespace std;

FileClass::FileClass() 
{

}

FileClass::~FileClass() 
{

}

int FileClass::OpenForWrite(const char *_fname) 
{
	m_File.open(_fname, ios::out|ios::binary);
	if(!m_File.is_open())
		return 0;
	return 1;
}

int FileClass::OpenForRead(const char *_fname) 
{
	m_File.open(_fname, ios::in|ios::binary);
	if(!m_File.is_open())
		return 0;
	return 1;
}

void FileClass::Close() 
{	
	m_File.close();
}

void FileClass::WriteChar(char _data) 
{
	m_File.put(_data);
}

void FileClass::WriteInt(int TData) {

	File.write(reinterpret_cast<char *>(&TData), sizeof(TData));
}


void FileClass::WriteStruct(void *TData, int TSize) {

	File.write(reinterpret_cast<char *>(TData), TSize);
}


void FileClass::WriteString(const char *TData) {

	File.write(TData, strlen(TData));
	File.put(0);
}


char FileClass::ReadChar() {

	return File.get();
}


int FileClass::ReadInt() {

	int Data;
	File.read(reinterpret_cast<char *>(&Data), sizeof(Data));

	return Data;
}


void FileClass::ReadStruct(void *TData, int TSize) {

	File.read(reinterpret_cast<char *>(TData), TSize);
}


void FileClass::ReadString(char *TData) {

	File.get(TData, 2147483647, 0);
	File.get();
}
